#{extends 'adminm/frame.html' /}

#{set 'moreScripts'}
<script src="@{'/public/javascripts/jquery-ui-1.8.10.custom.min.js'}" type="text/javascript" charset="utf-8"></script>
<script src="@{'/public/pager/jquery.pager.js'}" type="text/javascript" charset="utf-8"></script>
#{/set}
#{set 'moreStyles'}
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/pager/Pager.css'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/table.scss'}" />
#{/set}
#{set 'activeItem'}3#{/set}

<div class="navigationBar">
	<table>
		<tr>
			<td><img src="@{'/public/images/navigationHouse.gif'}"></td>
			<td><strong>当前位置：</strong></td>
			<td>
				<a href="/admin">首页</a>
				>>
				<a href="#">商品管理</a>
				>>
				<font class="current">品牌管理</font>
			</td>
		</tr>
	</table>
</div>
<script language="javascript">
$(function(){
	reloadTable();
});

//重新载入listtable。
function reloadTable() {
	var dataStr = getSearchCriteria();
	$.ajax({
		url: "/admin/brand/index",
		data: dataStr,
		type: "POST",
		dataType: "html",
		complete: function(XMLHttpRequest, textStatus, errorThrown) {
			if(textStatus == "error") {
				var errJson = eval("("+XMLHttpRequest.responseText+")");
				var errMsg = "操作失败，"+errJson.message;
				$("#errMsg").html(errMsg);
				alert(errMsg);
			} else {
				$("#tableDiv").html(XMLHttpRequest.responseText);
				initialPager();
			}
		}
	});
}

//组装查询条件与页码数据。
function getSearchCriteria(toPage) {
	var dataStr="";
	var elements = $(".queryBean");
	if(elements && elements.length!=0) {
		for(var i=0 ; i<elements.length ; i++) {
			if(dataStr) dataStr = dataStr+"&";
			if(elements[i].name != "queryBean.currentPage" || !toPage) {
				dataStr = dataStr + elements[i].name + "=" + $(elements[i]).val();
			}
		}
	}
	if(toPage) {
		if(dataStr) dataStr = dataStr+"&";
		dataStr = dataStr + "queryBean.currentPage=" + toPage;
	}
	return dataStr;
}

function updateBrandStatus(id, status) {
	$.ajax({
		url: "@{admin.Brands.updateBrandStatus}",
		data: "id="+id+"&status="+status,
		type: "POST",
		dataType: "json",
		complete: function(XMLHttpRequest, textStatus, errorThrown) {
			if(textStatus == "error") {
				var errJson = eval("("+XMLHttpRequest.responseText+")");
				var errMsg = "操作失败，"+errJson.message;
				$("#errMsg").html(errMsg);
				alert(errMsg);
			} else {
				reloadTable();
			}
		}
	});
}
</script>
<div id="errMsg" class="error">
	#{error 'errMsg'/}
</div>
<div class="list_criteria">
	<input type="hidden" id="currentPage" class="queryBean" name="queryBean.currentPage" value="1">
	每页
	<select class="queryBean" name="queryBean.quantityEachPage" onchange="reloadTable()">
		<option value="2">2</option>
		<option value="10" selected>10</option>
		<option value="25">25</option>
		<option value="50">50</option>
	</select>
	条记录&nbsp;&nbsp;
	按照
	<select class="queryBean" name="queryBean.orderby" onchange="reloadTable()">
		<option value="lastModifiedAt">修改日期</option>
		<option value="id">ID</option>
		<option value="name">名称</option>
		<option value="status">状态</option>
	</select>
	<select class="queryBean" name="queryBean.isDesc" onchange="reloadTable()">
		<option value="true" selected>降序</option>
		<option value="false">升序</option>
	</select>
	排序&nbsp;&nbsp;
	关键字<input class="queryBean" type="text" size="8" name="queryBean.keyword" onchange="reloadTable()">(ID\名称\描述)&nbsp;&nbsp;
</div>
<div id="tableDiv"></div>